package cn.edu.hqu.cst.zwl.ex3demo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    TextView tvShowAction;
    Button btnActivityAsListener,btnInnerClassAsListener,btnAnonymousClassAsListener;
    Button btnOuterClassAsListener,btnLambdaExpressionAsListener;
    Button btnShowSystemInfo,btnShowProgressBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvShowAction=findViewById(R.id.tv_main_activity_show_action);
        btnActivityAsListener=findViewById(R.id.btn_main_activity_activity_as_listener);
        btnInnerClassAsListener=findViewById(R.id.btn_main_activity_inner_class_as_listener);
        btnAnonymousClassAsListener=findViewById(R.id.btn_main_activity_anonymous_class_as_listener);
        btnLambdaExpressionAsListener=findViewById(R.id.btn_main_activity_lambda_expression_as_listener);
        btnOuterClassAsListener=findViewById(R.id.btn_main_activity_outer_class_as_listener);
        btnShowSystemInfo=findViewById(R.id.btn_main_activity_show_system_info);
        btnShowProgressBar=findViewById(R.id.btn_main_activity_show_progressbar);
        btnActivityAsListener.setOnClickListener(this);
        btnInnerClassAsListener.setOnClickListener(new InnerClassListener());

        btnAnonymousClassAsListener.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvShowAction.setText(R.string.str_anonymous_class_as_listener);
            }
        });

        btnLambdaExpressionAsListener.setOnClickListener(view->tvShowAction.setText(R.string.str_lambda_expression_as_listener));
        btnOuterClassAsListener.setOnClickListener(new OuterClassListener(tvShowAction));

        btnShowSystemInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("MainActivity","jlasdkf");
                Intent intent=new Intent(MainActivity.this,SystemInfoActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View v) {
        tvShowAction.setText(R.string.str_activity_as_listener);
    }

    class InnerClassListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            tvShowAction.setText(R.string.str_inner_class_as_listener);
        }
    }

    public void clickHandler(View v){
        tvShowAction.setText(R.string.str_bind_to_label);

    }
}


class OuterClassListener implements  View.OnClickListener{
    TextView tvShowText;
    public OuterClassListener(TextView tvShowText){
        this.tvShowText=tvShowText;
    }
    @Override
    public void onClick(View v) {
        tvShowText.setText(R.string.str_outer_class_as_listener);
    }
}